package com.weavernorth.humanresource;


import com.weavernorth.util.Logger4jUtil;
import org.apache.log4j.Logger;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.Calendar;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.general.BaseBean;
import weaver.general.Util;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import java.util.Iterator;

import static com.weavernorth.humanresource.util.commonUtil.getGzdqCode;


public class EntryAction implements Action {

//    public static Log log = LogFactory.getLog(EntryAction.class.getName());
    public Logger log = Logger4jUtil.getLoggerByName("/action/EntryAction/");

    @Override
    public String execute(RequestInfo requestInfo) {
        log.info("入职流程接口日志开始=======>");
        BaseBean bb = new BaseBean();
        RecordSet rs = new RecordSet();
        //工具类
        SalarRangeUtil salarRangeUtil = new SalarRangeUtil();
        boolean isSuccess = false;
        //获取当前日期
        Calendar now = Calendar.getInstance();
        int day = now.get(Calendar.DAY_OF_MONTH);
        String requestid = requestInfo.getRequestid();//请求ID
        String tablename = requestInfo.getRequestManager().getBillTableName();//表单名称
        log.info("tablename的值是:" + tablename + ", requestid" + requestid);

        //信息提示
        String strMessage = "";
        //紧急联系人
        String strJjlxr = "";
        //紧急联系人电话
        String strJjlxrdh = "";
        //码表rs
        RecordSet mbrs = new RecordSet();
        //查询码表sql
        String mbsql = "";
        //1.获取主表单数据
        String sql = " select * from " + tablename + " where requestid =" + requestid;
        log.info("sql的值是:" + sql + "\n");
        rs.execute(sql);


        //2.封装sap请求xml
        StringBuffer xml = new StringBuffer("");


        xml.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:soap:functions:mc-style\">");
        //xml.append("<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:urn='urn:sap-com:document:sap:soap:functions:mc-style'>");

        xml.append("<soapenv:Header/>");
        xml.append("<soapenv:Body>");


//      xml.append("<workflowid>"+rs.getString("id")+"</workflowid>");

        xml.append("<urn:Zhri072>");

        xml.append("<Return>");
        xml.append("<item>");

        xml.append("<Type></Type>");
        xml.append("<Id></Id>");
        xml.append("<Number></Number>");
        xml.append("<Message></Message>");
        xml.append("<LogNo></LogNo>");
        xml.append("<LogMsgNo></LogMsgNo>");
        xml.append("<MessageV1></MessageV1>");
        xml.append("<MessageV2></MessageV2>");
        xml.append("<MessageV3></MessageV3>");
        xml.append("<MessageV4></MessageV4>");
        xml.append("<Parameter></Parameter>");
        xml.append("<Row></Row>");
        xml.append("<Field></Field>");
        xml.append("<System></System>");

        xml.append("</item>");
        xml.append("</Return>");


        xml.append("<TYgrz>");
        xml.append("<item>");

        if (rs.next()) {

            strJjlxr = Util.null2String(rs.getString("jjlxr"));
            strJjlxrdh = Util.null2String(rs.getString("jjlxdh"));
            //zhri_072


            //*********************开始日期*****************************
            //开始时间


            xml.append("<Begda><![CDATA[" + rs.getString("rzsj") + "]]></Begda>");
            xml.append("<Endda>9999-12-31</Endda>");


            //出生国家
          //  String csgj = "CN";


            xml.append("<Gbort><![CDATA[" + rs.getString("hkszd") + "]]></Gbort>");


            //****************操作类型**************************
            String czlx = ""; //操作类型
            switch (rs.getInt("czlx")) {

                case 0:
                    czlx = "Z1";
                    break; //入职
                case 1:
                    czlx = "ZD";
                    break;  //退休返聘
            }

            xml.append("<Massn><![CDATA[" + czlx + "]]></Massn>");
            //xml.append("<Massn>" + rs.getString("cclx") + "</Massn>");

            log.info("操作类型的值:" + czlx + "\n");

            //********************************************
            //****************操作原因**************************

            String czyy = ""; //操作原因
            switch (rs.getInt("czyy")) {

                case 0:
                    czyy = "10";
                    break;

                case 1:
                    czyy = "20";
                    break;
            }

            xml.append("<Massg><![CDATA[" + czyy + "]]></Massg>");
            //xml.append("<Massg>" + rs.getString("czyy") + "</Massg>");

            log.info("操作原因的值:" + czyy + "\n");

            //********************************************


            //****************岗位**************************

            String gw = ""; //岗位
            mbsql = "select  jobtitlecode  from  hrmjobtitles where id = " + rs.getString("gw");
            mbrs.execute(mbsql);
            if (mbrs.next()) {

                gw = mbrs.getString("jobtitlecode");

                xml.append("<Plans><![CDATA[" + gw + "]]></Plans>");

            }

            log.info("岗位 sql的值:" + mbsql + "\n");
            log.info("岗位gw的值:" + gw + "\n");


            //*************************************************


//            xml.append("<Plans>" + rs.getString("gw") + "</Plans>");

            //****************人事范围**************************

            String rsfw = ""; //人事范围
            mbsql = "select  rsfwdm  from  uf_rsfw where id = " + rs.getString("rsfw");
            mbrs.execute(mbsql);
            if (mbrs.next()) {

                rsfw = mbrs.getString("rsfwdm");

                //xml.append("<Natio>"+ygz+"</Natio>");
                xml.append("<Werks><![CDATA[" + rsfw + "]]></Werks>");

            }

            log.info("人事范围 sql的值:" + mbsql + "\n");
            log.info("人事范围 的值:" + rsfw + "\n");


            //*************************************************


            //****************人事子范围**************************

            String rszfw = ""; //人事范围
            mbsql = "select  rszfwdm  from  uf_rszfw where id = " + rs.getString("rszfw");
            mbrs.execute(mbsql);
            if (mbrs.next()) {

                rszfw = mbrs.getString("rszfwdm");

                //xml.append("<Natio>"+ygz+"</Natio>");
                xml.append("<Btrtl><![CDATA[" + rszfw + "]]></Btrtl>");

            }

            log.info("人事子范围 sql的值:" + mbsql + "\n");
            log.info("人事子范围 的值:" + rszfw + "\n");


            //*************************************************


            //xml.append("<Werks>" + rs.getString("rsfw") + "</Werks>");
            //xml.append("<Btrtl>" + rs.getString("rszfw") + "</Btrtl>");

            //****************员工组**************************

            String ygz = ""; //员工组
            mbsql = "select  ygzdm  from  uf_ygz where id = " + rs.getString("ygz");
            mbrs.execute(mbsql);
            if (mbrs.next()) {

                ygz = mbrs.getString("ygzdm");

                //xml.append("<Natio>"+ygz+"</Natio>");
                xml.append("<Persg><![CDATA[" + ygz + "]]></Persg>");

            }

            log.info("ygz sql的值:" + mbsql + "\n");
            log.info("ygz 的值:" + ygz + "\n");

            //********************************************

            //****************员工子组**************************

            String ygzz = ""; //员工子组
            mbsql = "select  ygzzdm  from  uf_ygzz where id = " + rs.getString("ygzz");
            mbrs.execute(mbsql);
            if (mbrs.next()) {

                ygzz = mbrs.getString("ygzzdm");


                xml.append("<Persk><![CDATA[" + ygzz + "]]></Persk>");
            }

            log.info("ygzz sql的值:" + mbsql + "\n");
            log.info("ygzz 的值:" + ygzz + "\n");

            //********************************************


//            xml.append("<Persg>" + rs.getString("ygz") + "</Persg>");
//
//            xml.append("<Persk>" + rs.getString("ygzz") + "</Persk>");


            //****************工资范围**************************

            String gzfw = ""; //工资范围
            mbsql = "select  gzhsfw  from  uf_gzfw where id = " + rs.getString("gzfw");
            mbrs.execute(mbsql);
            if (mbrs.next()) {

                gzfw = mbrs.getString("gzhsfw");


                xml.append("<Abkrs><![CDATA[" + gzfw + "]]></Abkrs>");
            }

            log.info("工资范围 sql的值:" + mbsql + "\n");
            log.info("工资范围 的值:" + gzfw + "\n");

            //********************************************
            //zm 增加,判断工资范围是否锁定 开始
            String strSxrq = Util.null2String(rs.getString("sxrq"));
            String strLockMess = salarRangeUtil.judgeLock(gzfw, strSxrq);
            log.info("工资核算范围返回信息:" + strLockMess);
            if (!"".equals(strLockMess)) {
                strLockMess = strLockMess + "薪资核算结束后，工资范围解除锁定，流程可以继续提交";
                requestInfo.getRequestManager().setMessagecontent(strLockMess);
                return FAILURE_AND_CONTINUE;

            }
            //zm 增加,判断工资范围是否锁定 结束


            xml.append("<Nachn><![CDATA[" + rs.getString("x") + "]]></Nachn>");


            xml.append("<Vorna><![CDATA[" + rs.getString("m") + "]]></Vorna>");


            //xml.append("<Nachn>" + rs.getString("x") + "</Nachn>");
            //xml.append("<Name2>"+rs.getString("x")+"</Name2>");
            //xml.append("<Inits>"+rs.getString("x")+"</Inits>");
            xml.append("<Gbdat><![CDATA[" + rs.getString("csrq") + "]]></Gbdat>"); //出生日期


            //****************性别**************************
            String xb = ""; //性别
            switch (rs.getInt("xb")) {

                case 0:
                    xb = "1";
                    break;
                case 1:
                    xb = "2";
                    break;
            }


            xml.append("<Gesch><![CDATA[" + xb + "]]></Gesch>"); //性别
            //xml.append("<Gbdat>"+  +"</Gbdat>");


            //xml.append("<Gblnd>"+rs.getString("x")+"</Gblnd>");
            //xml.append("<Gbort>"+rs.getString("hkszd")+"</Gbort>");

            //****************国籍**************************

            String gj = ""; //国籍
            mbsql = "select  gjdmsap  from  uf_gj  where id = " + rs.getString("gj");
            mbrs.execute(mbsql);
            if (mbrs.next()) {

                gj = mbrs.getString("gjdmsap");

                xml.append("<Natio><![CDATA[" + gj + "]]></Natio>");

            }
            xml.append("<Gblnd><![CDATA[" + gj + "]]></Gblnd>");

            log.info("gjdmsap sql的值:" + mbsql + "\n");
            log.info("gjdmsap 的值:" + gj + "\n");


            //****************婚姻状况**************************
            String hyzk = ""; //婚姻状况*
            switch (rs.getInt("hyzk")) {

                case 0:
                    hyzk = "0";
                    break;
                case 1:
                    hyzk = "1";
                    break;
                case 2:
                    hyzk = "9";
                    break;
            }


            xml.append("<Famst><![CDATA[" + hyzk + "]]></Famst>");

            log.info("hyzk的值:" + hyzk + "\n");
            //xml.append("<Anzkd>"+rs.getString("x")+"</Anzkd>");


            //****************籍贯**************************


            String jg = ""; //籍贯
            mbsql = "select  jgdm  from  uf_jg  where id = " + rs.getString("jg");
            mbrs.execute(mbsql);
            if (mbrs.next()) {

                jg = mbrs.getString("jgdm");

                xml.append("<Gbdep><![CDATA[" + jg + "]]></Gbdep>");

            }

            log.info("jgdm sql的值:" + mbsql + "\n");
            log.info("jgdm 的值:" + jg + "\n");


            //xml.append("<Konfe>"+rs.getString("x")+"</Konfe>");
            //xml.append("<Famdt>"+rs.getString("x")+"</Famdt>");


            //****************户口类型**************************
            String hklx = ""; //户口类型
            switch (rs.getInt("hklx")) {

                case 0:
                    hklx = "1";
                    break;
                case 1:
                    hklx = "2";
                    break;
                case 2:
                    hklx = "3";
                    break;
            }

            xml.append("<Hukot><![CDATA[" + hklx + "]]></Hukot>");

            log.info("hklx的值:" + hklx + "\n");


            //****************民族**************************
            String mz = ""; //民族
            mbsql = "select  mzdmsap  from  uf_mz  where id = " + rs.getString("mz");
            mbrs.execute(mbsql);
            if (mbrs.next()) {

                mz = mbrs.getString("mzdmsap");

                xml.append("<Racky><![CDATA[" + mz + "]]></Racky>");

            }

            //log.info("mzdmsap sql的值:" + mbsql +"\n");
            //log.info("mzdmsap 的值:" + mz +"\n");


            //****************是否社聘**************************
            String sfsp = ""; //是否社聘
            switch (rs.getInt("sfsp")) {

                case 0:
                    sfsp = "10";
                    break;
                case 1:
                    sfsp = "20";
                    break;

            }

            xml.append("<Zsp><![CDATA[" + sfsp + "]]></Zsp>");

            log.info("是否社聘sfsp的值:" + sfsp + "\n");


            //******************************************


            //xml.append("<Zsp>"+rs.getInt("sfsp")+"</Zsp>");
            //获取证件类型
            String strZjlx=Util.null2String(rs.getString("zjlx"));
            log.info("");
            //护照类型
            if("2".equals(strZjlx)){
                xml.append("<Zhzbh><![CDATA["+ rs.getString("zjh") + "]]></Zhzbh>");
                xml.append("<Icnum></Icnum>");
            }else {
                xml.append("<Icnum><![CDATA[" + rs.getString("zjh") + "]]></Icnum>");
            }

            //xml.append("<Zhzbh>"+rs.getString("x")+"</Zhzbh>");


            //xml.append("<Auth1>"+rs.getString("x")+"</Auth1>");
            //xml.append("<Isspl>"+rs.getString("x")+"</Isspl>");
            //xml.append("<Usefr>"+rs.getString("x")+"</Usefr>");
            //xml.append("<Useto>"+rs.getString("x")+"</Useto>");


            //****************政治面貌**************************

            String zzmm = ""; //政治面貌
            mbsql = "select  zzmmdm  from  uf_zzmm  where id = " + rs.getString("zzmm");
            mbrs.execute(mbsql);
            if (mbrs.next()) {

                zzmm = mbrs.getString("zzmmdm");

                xml.append("<Pcode><![CDATA[" + zzmm + "]]></Pcode>");

            }

            log.info("zzmmdm sql的值:" + mbsql + "\n");
            log.info("zzmmdm 的值:" + zzmm + "\n");


            //xml.append("<Pcode>"+rs.getString("zzmm")+"</Pcode>");
            //xml.append("<Joinu>"+rs.getString("x")+"</Joinu>");
            //xml.append("<Intr1>"+rs.getString("x")+"</Intr1>");
            xml.append("<Zhtks><![CDATA[" + rs.getString("htksrq") + "]]></Zhtks>");
            xml.append("<Ctnum><![CDATA[" + rs.getString("hth") + "]]></Ctnum>");


            //****************合同类型*************************

            String htlx = ""; //合同类型
            mbsql = "select  htlxbm  from  uf_htlx  where id = " + rs.getString("htlx");
            mbrs.execute(mbsql);
            if (mbrs.next()) {

                htlx = mbrs.getString("htlxbm");

                xml.append("<Cttyp><![CDATA[" + htlx + "]]></Cttyp>");

            }

            log.info("合同类型htlx sql的值:" + mbsql + "\n");
            log.info("合同类型htlx 的值:" + htlx + "\n");

            //******************************************


            //xml.append("<Cttyp>"+rs.getString("htlx")+"</Cttyp>");
            xml.append("<Ctedt><![CDATA[" + rs.getString("htjsrq") + "]]></Ctedt>");
            xml.append("<Usrid><![CDATA[" + rs.getString("grdh") + "]]></Usrid>");
            //xml.append("<Zspzcls>"+rs.getString("x")+"</Zspzcls>");
            //xml.append("<Zspzcjb>"+rs.getString("x")+"</Zspzcjb>");


            //班次信息,默认0800
            xml.append("<Schkz>0800</Schkz>");

            //默认值为9
            xml.append("<Zterf>9</Zterf>");
            xml.append("<Dar01>Z1</Dar01>");
            xml.append("<Dat01><![CDATA[" + rs.getString("sccjgzrq") + "]]></Dat01>");
            xml.append("<Dar02>Z2</Dar02>");
            xml.append("<Dat02><![CDATA[" + rs.getString("jrjtrq") + "]]></Dat02>");
            xml.append("<Dar03>Z3</Dar03>");
            xml.append("<Dat03><![CDATA[" + rs.getString("jrgsrq") + "]]></Dat03>");

            //****************银行名称**************************


            String yhmc = ""; //银行名称
            mbsql = "select  yxdm  from  uf_yhmc  where id = " + rs.getString("yhmc");
            mbrs.execute(mbsql);
            if (mbrs.next()) {

                yhmc = mbrs.getString("yxdm");

                xml.append("<Bankl><![CDATA[" + yhmc + "]]></Bankl>");

            }

            //log.info("mzdmsap sql的值:" + mbsql +"\n");
            //log.info("mzdmsap 的值:" + mz +"\n");


            //********************************************************
            //xml.append("<Bankl>"+rs.getString("yhmc")+"</Bankl>");
            xml.append("<Bankn><![CDATA[" + rs.getString("yxkh") + "]]></Bankn>");
            //xml.append("<Pernr>"+rs.getString("x")+"</Pernr>");


            // xml.append("<Zbetrg1>" + rs.getDouble("sbjs") + "</Zbetrg1>");// 社保基数
            xml.append("<Zbetrg2><![CDATA[" + rs.getDouble("gjjjs") + "]]></Zbetrg2>");//公积金基数
            xml.append("<Zgz><![CDATA[" + rs.getString("gzffgs") + "]]></Zgz>");
            xml.append("<Zzsb><![CDATA[" + rs.getString("sbjngs") + "]]></Zzsb>");
            xml.append("<Zzgjj><![CDATA[" + rs.getString("gjjjngs") + "]]></Zzgjj>");
            xml.append("<Kst01></Kst01>");   //成本中心
            String strEmail = Util.null2String(rs.getString("adzh")) + "@chinaerdos.com";
            xml.append("<Usrid1><![CDATA[" + strEmail + "]]></Usrid1>");
            xml.append("<Usrid2><![CDATA[" + Util.null2String(rs.getString("adzh")) + "]]></Usrid2>");
            //region [2021-03-04：新增字段]
            //获取试用期
            String strSyq = Util.null2String(rs.getString("syq"));
            String syq="";
            if("0".equals(strSyq)){//试用期3个月
                syq="3";
            }else if("1".equals(strSyq)){//试用期6个月
                syq="6";
            }else if("2".equals(strSyq)){//试用期2个月
                syq="2";
            }else{
                syq="0";
            }
            xml.append("<Prbzt>"+syq+"</Prbzt>");
            xml.append("<Ernpn></Ernpn>");
            xml.append("<Eenpn></Eenpn>");
            xml.append("<Intr2></Intr2>");
            //endregion
        }
        xml.append("</item>");
        xml.append("</TYgrz>");


        //===========T_0022 教育经历信息= _dt1===================

        RecordSet dt1rs = new RecordSet();

        //1.获取子表单dt1数据
        String dt1sql = " select  * from " + tablename + "_dt1 dt1 " + " where dt1.mainid=( select id from " + tablename + " mt where mt.requestid =" + requestid + ")";

        log.info("dt1sql的值是:" + dt1sql + "\n");
        dt1rs.execute(dt1sql);


        xml.append("<T_0022>");

        while (dt1rs.next()) {
            xml.append("<item>");


            xml.append("<Zxlks><![CDATA[" + dt1rs.getString("rxrq") + "]]></Zxlks>");
            xml.append("<Zxljs><![CDATA[" + dt1rs.getString("byrq") + "]]></Zxljs>");

            //****************学历*************************

            String xl = ""; //学历
            mbsql = "select  xlbm  from  uf_xl  where id = " + dt1rs.getString("xl");
            mbrs.execute(mbsql);
            if (mbrs.next()) {

                xl = mbrs.getString("xlbm");

                xml.append("<Slart><![CDATA[" + xl + "]]></Slart>");

            }
            log.info("学历xl sql的值:" + mbsql + "\n");
            log.info("学历xl 的值:" + xl + "\n");

            //******************************************
            xml.append("<Insti><![CDATA[" + dt1rs.getString("yxpxjg") + "]]></Insti>");
            //****************学院性质**************************
            String yxxz = ""; //学院性质
            switch (dt1rs.getInt("yxxz")) {

                case 0:
                    yxxz = "010";
                    break;
                case 1:
                    yxxz = "020";
                    break;

            }
            xml.append("<Insat><![CDATA[" + yxxz + "]]></Insat>");
            log.info("学院性质xyxz的值:" + yxxz + "\n");
            xml.append("<Anzkl><![CDATA[" + dt1rs.getString("xz") + "]]></Anzkl>");
            xml.append("<Fach3><![CDATA[" + dt1rs.getString("sxzy") + "]]></Fach3>");


            //****************学位**************************
            String xw = ""; //学位
            switch (dt1rs.getInt("xw")) {

                case 0:
                    xw = "10";
                    break;
                case 1:
                    xw = "01";
                    break;
                case 2:
                    xw = "00";
                    break;
                case 3:
                    xw = "52";
                    break;


            }

            xml.append("<Slabs><![CDATA[" + xw + "]]></Slabs>");

            log.info("学位xw的值:" + xw + "\n");


            //******************************************


            xml.append("<Acaqm><![CDATA[" + dt1rs.getInt("zgxlbs") + "]]></Acaqm>");


            //空值
            xml.append("<Acqid></Acqid>");
            xml.append("<Acaqd></Acaqd>");
            xml.append("<Accid></Accid>");
            xml.append("<Acacd></Acacd>");


            xml.append("<Acacm><![CDATA[" + dt1rs.getInt("zgxwbs") + "]]></Acacm>");


//            //****************证书*************************
//
//            String zs=""; //证书
//            mbsql = "select  xwzsbm  from  uf_xwzs  where id = " + dt1rs.getString("zs");
//            mbrs.execute(mbsql);
//            if(mbrs.next()) {
//
//                xl=mbrs.getString("xwzsbm");
//
//                xml.append("<Slart>"+zs+"</Slart>");
//
//            }
//
//            log.info("证书 sql的值:" + mbsql +"\n");
//            log.info("证书zs 的值:" + zs +"\n");

            //******************************************

            xml.append("</item>");

        }

        xml.append("</T_0022>");


        //===========T_0530 五险一金====================


        //****************公积金码表转码*************************

        String gjjjnddm = ""; //公积金缴纳地代码
        mbsql = "select  jnddm  from  uf_gjjmb  where id = " + rs.getString("gjjjnd");
        mbrs.execute(mbsql);
        if (mbrs.next()) {

            gjjjnddm = mbrs.getString("jnddm");

            //xml.append("<Slart>"+jnddm+"</Slart>");

        }

        log.info("公积金缴纳地代码 sql的值:" + mbsql + "\n");
        log.info("公积金缴纳地代码gjjjnddm 的值:" + gjjjnddm + "\n");

        //******************************************


        //公积金
        RecordSet dt3rs = new RecordSet();

        //1.获取子表单dt3数据
        String dt3sql = " select  * from " + tablename + "_dt3 dt3 " + " where dt3.mainid=( select id from " + tablename + " mt where mt.requestid =" + requestid + ")  and dt3.bxlx=5";

        log.info("dt3sql的值是:" + dt3sql + "\n");
        dt3rs.execute(dt3sql);
        xml.append("<T_0530>");
        if (dt3rs.next()) {

            int bxlx = dt3rs.getInt("BXLX");
            String bxlxdm = dt3rs.getString("BXLXDM");


            //****************行业XY转码**************************
            String xy = ""; //行业
            //根据字段名称得到fieldid
            String strXyFieldid = salarRangeUtil.getFieldid(tablename, tablename + "_dt3", "xy");
            //得到对应的值
            xy = salarRangeUtil.getFieldValue(strXyFieldid, Util.null2String(dt3rs.getString("XY")));
//            switch (dt3rs.getInt("XY")) {
//
//                case 0:
//                    xy = "01";
//                    break;
//                case 1:
//                    xy = "02";
//                    break;
//                case 2:
//                    xy = "03";
//                    break;
//                case 3:
//                    xy = "04";
//                    break;
//                case 4:
//                    xy = "16";
//                    break;
//            }


            log.info("行业xy的值:" + xy + "\n");

            //******************************************


            //****************组Z转码**************************

            String z = ""; //组

            //根据字段名称得到fieldid
            String strZFieldid = salarRangeUtil.getFieldid(tablename, tablename + "_dt3", "z");
            //得到对应的值
            z = salarRangeUtil.getFieldValue(strZFieldid, Util.null2String(dt3rs.getString("Z")));

//            switch (dt3rs.getInt("Z")) {
//
//                case 0:
//                    z = "GR01";
//                    break;
//                case 1:
//                    z = "GR02";
//                    break;
//            }


            log.info("组z的值:" + z + "\n");

            //******************************************


            //****************级别jb转码**************************
            String jb = ""; //级别

            //根据字段名称得到fieldid
            String strJbFieldid = salarRangeUtil.getFieldid(tablename, tablename + "_dt3", "jb");
            //得到对应的值
            jb = salarRangeUtil.getFieldValue(strJbFieldid, Util.null2String(dt3rs.getString("JB")));
//            switch (dt3rs.getInt("JB")) {
//
//                case 0:
//                    jb = "01";
//                    break;
//                case 1:
//                    jb = "02";
//                    break;
//                case 2:
//                    jb = "03";
//                    break;
//                case 3:
//                    jb = "04";
//                    break;
//                case 4:
//                    jb = "05";
//                    break;
//            }


            log.info("级别jb的值:" + jb + "\n");

            //******************************************


            //****************缴纳方式转码**************************
            String jnfs = ""; //缴纳方式
            switch (dt3rs.getInt("jnfs")) {

                case 0:
                    jnfs = "1";
                    break;
                case 1:
                    jnfs = "2";
                    break;
                case 2:
                    jnfs = "3";
                    break;
                case 3:
                    jnfs = "4";
                    break;
                case 4:
                    jnfs = "5";
                    break;
            }


            log.info("缴纳方式:" + jnfs + "\n");

            //******************************************



            xml.append("<item>");

            xml.append("<Pegdap><![CDATA[" + rs.getString("gjjjnrq") + "]]></Pegdap>");     //公积金缴纳日期
            xml.append("<Conarp><![CDATA[" + gjjjnddm + "]]></Conarp>");   //公积金缴纳地  转码
            xml.append("<Conty2><![CDATA[" + xy + "]]></Conty2>");     //行业
            xml.append("<Congr2><![CDATA[" + z + "]]></Congr2>");      //组
            xml.append("<Conlv2><![CDATA[" + jb + "]]></Conlv2>");     //级别
            xml.append("<Pbyer><![CDATA[" + jnfs + "]]></Pbyer>");    //缴纳方式


            xml.append("</item>");


        }
        xml.append("</T_0530>");


        /*新增税收分组等字段*/
        String strSsfz = Util.null2String(rs.getString("ssfzz"));
        //erp代码
        String strSsfzDm = "";
        //根据编码得到税收分组代码
        String ssSql = "select erssfz from uf_ssfzmb where id=? ";
        mbrs.executeQuery(ssSql, strSsfz);
        if (mbrs.next()) {
            strSsfzDm = Util.null2String(mbrs.getString("erssfz"));
        }
        //税收员工类型
        String strSsyglx = Util.null2String(rs.getString("ssyglx"));
        String strSsyglxTosap = "2";
        if ("0".equals(strSsyglx)) {
            strSsyglxTosap = "1";
        }
        //税收员工类型
        String strSflwsd = Util.null2String(rs.getString("sflwsd"));
        String strSflwsdTosap = "";
        if ("0".equals(strSflwsd)) {
            strSflwsdTosap = "X";
        }


        xml.append(" <T_0531>");
        xml.append(" <item>");
        xml.append("<Begda><![CDATA[" + Util.null2String(rs.getString("rzsj")) + "]]></Begda>");
        xml.append(" <Taxgp><![CDATA[" + strSsfzDm + "]]></Taxgp>");
        xml.append("<Txgrn><![CDATA[" + strSsyglxTosap + "]]></Txgrn>");
        xml.append("<Labwk><![CDATA[" + strSflwsdTosap + "]]></Labwk>");
        xml.append("</item>");
        xml.append("</T_0531>");
        /*新增税收分组等字段*/

        //****************社保码表转码*************************

        String sbjnddm = ""; //社保缴纳地代码
        mbsql = "select  jnddm  from  uf_sbmb  where id = " + rs.getString("sbjnd");
        mbrs.execute(mbsql);
        if (mbrs.next()) {

            sbjnddm = mbrs.getString("jnddm");

            //xml.append("<Slart>"+jnddm+"</Slart>");

        }

        log.info("社保缴纳地代码 sql的值:" + mbsql + "\n");
        log.info("社保缴纳地代码sbjnddm 的值:" + sbjnddm + "\n");

        //******************************************


        //五险
        RecordSet dt32rs = new RecordSet();

        //养老社保基数
        String strYl = "";
        //失业社保基数
        String strSy = "";
        //医疗
        String strYil = "";
        //工商
        String strGs = "";
        //孕产
        String strYunC = "";


        //1.获取子表单dt1数据
        String dt32sql = " select  * from " + tablename + "_dt3 dt3 " + " where dt3.mainid=( select id from " + tablename + " mt where mt.requestid =" + requestid + ")  and dt3.bxlx in (0,1,2,3,4) ";

        log.info("dt32sql的值是:" + dt32sql + "\n");
        dt32rs.execute(dt32sql);

        xml.append("<T_0532>");

        while (dt32rs.next()) {

            int bxlx = dt32rs.getInt("BXLX");
            //社保基数
            String strSbjs = Util.null2String(dt32rs.getString("sbjs"));
            if (bxlx == 0) {
                strYl = strSbjs;
            } else if (bxlx == 1) {
                strSy = strSbjs;
            } else if (bxlx == 2) {
                strYil = strSbjs;
            } else if (bxlx == 3) {
                strGs = strSbjs;
            } else if (bxlx == 4) {
                strYunC = strSbjs;
            }
            String bxlxdm = dt32rs.getString("BXLXDM"); //保险代码
            //int xy=dt32rs.getInt("XY");     //行业
            //int z=dt32rs.getInt("Z");      //组
            //int jb=dt32rs.getInt("JB");     //级别
            //int jnfs=dt32rs.getInt("JNFS");


            //****************行业XY转码**************************
            String xy = ""; //行业

            //根据字段名称得到fieldid
            String strxyFieldid = salarRangeUtil.getFieldid(tablename, tablename + "_dt3", "xy");
            //得到对应的值
            xy = salarRangeUtil.getFieldValue(strxyFieldid, Util.null2String(dt32rs.getString("xy")));
//            switch (dt32rs.getInt("XY")) {
//
//                case 0:
//                    xy = "01";
//                    break;
//                case 1:
//                    xy = "02";
//                    break;
//                case 2:
//                    xy = "03";
//                    break;
//                case 3:
//                    xy = "04";
//                    break;
//                case 4:
//                    xy = "16";
//                case 5:
//                    xy = "20";
//                    break;
//            }


            log.info("行业xy的值:" + xy + "\n");

            //******************************************


            //****************组Z转码**************************
            String z = ""; //组
            //根据字段名称得到fieldid
            String strZFieldid = salarRangeUtil.getFieldid(tablename, tablename + "_dt3", "z");
            //得到对应的值
            z = salarRangeUtil.getFieldValue(strZFieldid, Util.null2String(dt32rs.getString("Z")));


//            switch (dt32rs.getInt("Z")) {
//
//                case 0:
//                    z = "GR01";
//                    break;
//                case 1:
//                    z = "GR02";
//                    break;
//            }


            log.info("组z的值:" + z + "\n");

            //******************************************


            //****************级别jb转码**************************
            String jb = ""; //级别
            switch (dt32rs.getInt("JB")) {

                case 0:
                    jb = "01";
                    break;
                case 1:
                    jb = "02";
                    break;
                case 2:
                    jb = "03";
                    break;
                case 3:
                    jb = "04";
                    break;
                case 4:
                    jb = "05";
                    break;
            }


            log.info("级别jb的值:" + jb + "\n");


            //******************************************


            //****************缴纳方式转码**************************
            String jnfs = ""; //缴纳方式
            switch (dt32rs.getInt("jnfs")) {

                case 0:
                    jnfs = "1";
                    break;
                case 1:
                    jnfs = "2";
                    break;
                case 2:
                    jnfs = "3";
                    break;
                case 3:
                    jnfs = "4";
                    break;
                case 4:
                    jnfs = "5";
                    break;
            }


            log.info("缴纳方式:" + jnfs + "\n");

            //******************************************


            xml.append("<item>");
            xml.append("<Begdas><![CDATA[" + rs.getString("sbjnrq") + "]]></Begdas>");    //社保缴纳日期
            xml.append("<Conar><![CDATA[" + sbjnddm + "]]></Conar>");    //社保缴纳地
            xml.append("<Intyp><![CDATA[" + bxlxdm + "]]></Intyp>");     //保险类型代码
            xml.append("<Conty1><![CDATA[" + xy + "]]></Conty1>");    //行业
            xml.append("<Congr1><![CDATA[" + z + "]]></Congr1>");     //组
            xml.append("<Conlv1><![CDATA[" + jb + "]]></Conlv1>");   //级别
            xml.append("<Pbyer><![CDATA[" + jnfs + "]]></Pbyer>");
            xml.append("</item>");


        }
        xml.append("</T_0532>");

        /**社保基数*/
        xml.append("<TSbjs>");
        xml.append("<item>");
        xml.append(" <Zzyanglaojs><![CDATA[" + strYl + "]]></Zzyanglaojs>");
        xml.append("<Zzyiliaojs><![CDATA[" + strYil + "]]></Zzyiliaojs>");
        xml.append(" <Zzshiyejs><![CDATA[" + strSy + "]]></Zzshiyejs>");
        xml.append("<Zzgongshangjs><![CDATA[" + strGs + "]]></Zzgongshangjs>");
        xml.append("<Zzshengyujs><![CDATA[" + strYunC + "]]></Zzshengyujs>");
        xml.append("</item>");
        xml.append("</TSbjs>");
        /**社保基数*/
        //===========T_9110 未知====================
        xml.append("<T_9110>");
        xml.append("<item>");

        //空值
        xml.append("<Zzsmc></Zzsmc>");
        xml.append("<Zfzsj></Zfzsj>");
        xml.append("<Zzjh></Zzjh>");
        xml.append("<Zdqsj></Zdqsj>");
        xml.append("<Zfssj></Zfssj>");
        xml.append("<Zyxq></Zyxq>");
        xml.append("<Zfzjg></Zfzjg>");
        xml.append("<Zzcjl></Zzcjl>");

        xml.append("</item>");
        xml.append("</T_9110>");

        //region [=====T_9111 工作经历=====]
        RecordSet dt2rs = new RecordSet();
        //1.获取子表单dt2数据
        String dt2sql = " select  * from " + tablename + "_dt2 dt2 " + " where dt2.mainid=( select id from " + tablename + " mt where mt.requestid =" + requestid + ")";
        //select  * from formtable_main_77_dt2 dt2 where dt2.mainid = (select id from formtable_main_77 mt  where mt.requestid =316316)
        log.info("dt2sql的值是:" + dt2sql + "\n");
        dt2rs.execute(dt2sql);
        xml.append("<T_9111>");
        while (dt2rs.next()) {
            xml.append("<item>");
            xml.append("<Begda><![CDATA[" + dt2rs.getString("ksrq") + "]]></Begda>");
            xml.append("<Endda><![CDATA[" + dt2rs.getString("jsrq") + "]]></Endda>");
            xml.append("<Zgzdw><![CDATA[" + dt2rs.getString("gzdw") + "]]></Zgzdw>");
            xml.append("<Zbm><![CDATA[" + dt2rs.getString("gzbm") + "]]></Zbm>");
            xml.append("<Zgw><![CDATA[" + dt2rs.getString("gzgw") + "]]></Zgw>");
            //xml.append("<Zzw>"+dt2rs.getString("x")+"</Zzw>");
            //xml.append("<Zzjzqk>"+dt2rs.getString("x")+"</Zzjzqk>");
            //xml.append("<Zmzxx>"+dt2rs.getString("x")+"</Zmzxx>");
            xml.append("<Zbz><![CDATA[" + dt2rs.getString("bz") + "]]></Zbz>");
            //xml.append("<Zzj>"+dt2rs.getString("x")+"</Zzj>");
            //xml.append("<Zzc>"+dt2rs.getString("x")+"</Zzc>");
            //xml.append("<Zsxsj>"+dt2rs.getString("x")+"</Zsxsj>");
            //xml.append("<Zrxwj>"+dt2rs.getString("x")+"</Zrxwj>");
            //xml.append("<Zwjm>"+dt2rs.getString("x")+"</Zwjm>");
            //xml.append("<Zzwgb>"+dt2rs.getString("x")+"</Zzwgb>");
            //xml.append("<Zsfxz>"+dt2rs.getString("x")+"</Zsfxz>");
            //xml.append("<Zxzjb>"+dt2rs.getString("x")+"</Zxzjb>");
            //xml.append("<Zxzfp>"+dt2rs.getString("x")+"</Zxzfp>");
            //xml.append("<Zzmr>"+dt2rs.getString("x")+"</Zzmr>");
            //xml.append("<Zzmwfs>"+dt2rs.getString("x")+"</Zzmwfs>");
            xml.append("</item>");
        }
        xml.append("</T_9111>");
        //endregion
        //region [====T_9112 地址信息====]
        xml.append("<T_9112>");
        //todo:待定
//        xml.append("<item>");
//        xml.append("<Zdzlb></Zdzlb>");
//        xml.append("<Zxxdz></Zxxdz>");
//        xml.append("<Zygzdw></Zygzdw>");
//        xml.append("</item>");
        xml.append("</T_9112>");
        //endregion
        //region [=====T_9124 成员关系信息dt4=====]
        RecordSet dt4rs = new RecordSet();
        //1.获取子表单dt4数据
        String dt4sql = " select  * from " + tablename + "_dt4 dt4 " + " where dt4.mainid=( select id from " + tablename + " mt where mt.requestid =" + requestid + ")";
        //select  * from formtable_main_77_dt4 dt4 where dt4.mainid = (select id from formtable_main_77 mt  where mt.requestid =316316)
        log.info("dt4sql的值是:" + dt4sql + "\n");
        dt4rs.execute(dt4sql);
        xml.append("<T_9124>");
        //紧急联系人信息
        xml.append("<item>");
        xml.append("<Zcygx>60</Zcygx>");
        xml.append("<Zxm><![CDATA[" + strJjlxr + "]]></Zxm>");
        xml.append("<Zxb></Zxb>");
        xml.append("<Zlxys><![CDATA[" + strJjlxrdh + "]]></Zlxys>");
        xml.append("<Zxgzfw></Zxgzfw>");
        xml.append("</item>");
        while (dt4rs.next()) {
            xml.append("<item>");
            //****************成员关系*************************
            String cygx = ""; //成员关系
            mbsql = "select  cygxdm  from  uf_cygx  where id = " + dt4rs.getString("cygx");
            mbrs.execute(mbsql);
            if (mbrs.next()) {
                cygx = mbrs.getString("cygxdm");
                xml.append("<Zcygx><![CDATA[" + cygx + "]]></Zcygx>");
            }
            log.info("成员关系cygx sql的值:" + mbsql + "\n");
            log.info("成员关系cygx 的值:" + cygx + "\n");
            //******************************************
            String xb = ""; //性别
            switch (dt4rs.getInt("xb")) {
                case 0:
                    xb = "10";
                    break;
                case 1:
                    xb = "20";
                    break;
            }
            //xml.append("<Zcygx>"+dt4rs.getString("cygx")+"</Zcygx>");
            xml.append("<Zxm><![CDATA[" + dt4rs.getString("xm") + "]]></Zxm>");
            xml.append("<Zxb><![CDATA[" + xb + "]]></Zxb>");
            xml.append("<Zlxys><![CDATA[" + dt4rs.getString("lxfs") + "]]></Zlxys>");
            xml.append("<Zxgzfw><![CDATA[" + dt4rs.getString("xgzdw") + "]]></Zxgzfw>");
            xml.append("</item>");
        }
        xml.append("</T_9124>");
        //endregion

        //region [====T_9137 工作地区-new====]
        xml.append("<T_9137>");
        xml.append("<item>");
        xml.append("<Zgzdq><![CDATA[" + getGzdqCode(rs.getString("gzdq"))+ "]]></Zgzdq>");
        xml.append("<Zmark></Zmark>");
        xml.append("</item></T_9137>");
        //endregion
        //region [====T_9139 员工类型机构类型-new====]
        xml.append("<T_9139>");
//        xml.append("<item>");
//        xml.append("<Zyglx><![CDATA[" + rs.getString("yglx") + "]]></Zyglx>");
//        String strJglx=rs.getString("jglx");
//        if(!"".equals(strJglx)){
//            xml.append("<Zjglx>"+Integer.parseInt(strJglx)*10+"</Zjglx>");
//        }else{
//            xml.append("<Zjglx></Zjglx>");
//        }
//        xml.append("</item>");
        xml.append("</T_9139>");
        //endregion
        xml.append("</urn:Zhri072>");
        xml.append("</soapenv:Body>");
        xml.append("</soapenv:Envelope>");
        log.info("入职XML的值是:" + xml.toString());
        //CommonToSapUtil commonToSapUtil=new CommonToSapUtil();
        try {
            //3.推送数据
            String rzurl = Util.null2String(bb.getPropValue("personnel-erdos", "rzurl"));
            //String responseXml=   commonToSapUtil.sendPost("rzurl", xml.toString(), "utf-8");
            String responseXml = salarRangeUtil.sendPost(rzurl, xml.toString(), "utf-8");
            log.info("入职SAP返回的值是:" + responseXml.toString());
            //===========SAP 返回解析====================
            String strWorkcode = "";
            //xmlStr为上图格式的字符串
            String EPernr = "";//员工编码
            StringBuffer strbuMess = new StringBuffer();
            Document doc = null;
            try {
                doc = DocumentHelper.parseText(responseXml);
                Iterator<Element> its2 = doc.selectNodes("//Type").iterator();
                Iterator<Element> its3 = doc.selectNodes("//Message").iterator();
                while (its2.hasNext() && its3.hasNext()) {
                    Element element = its2.next();
                    Element element2 = its3.next();
                    String testType = element.getText();
                    String strMess = element2.getText();

                    if (!"".equals(testType) && "S".equals(testType)) {
                        isSuccess = true;
                        log.info("testType值为:" + testType + "\n");

                    }
                    if (!"".equals(testType) && "E".equals(testType)) {
                        strbuMess.append(strMess);
                    }

                }
                //返回值失败时,则提示失败
//                if ("E".equals(testType)) {
//                    Iterator<Element> its3 = doc.selectNodes("//Message").iterator();
//                    while (its3.hasNext()) {
//                        Element element2 = its3.next();
//                        strMessage = element2.getText();
//                        if (!"".equals(strMessage)) {
//                            break;
//                        }
//                    }
//
//                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            String updatesql = "";
            String returnEPernr = "";
            //入职成功,获取EPernr员工编号
            if (isSuccess && doc.selectSingleNode("//EPernr") != null) {
                returnEPernr = Util.null2String(doc.selectSingleNode("//EPernr").getText());
                //判断员工号是否为空
                if (!"".equals(returnEPernr)) {
                    EPernr = returnEPernr;
                    log.info("员工编号:" + returnEPernr + "\n");
                    updatesql = "update " + tablename + " set hth=" + EPernr + " where requestid=" + requestid;
                    rs.executeQuery(updatesql);
                    log.info("update员工号 sql的值:" + updatesql + "\n");
                    log.info("EPernr员工号 的值:" + EPernr + "\n");
                } else {
                    //没有员工编号
                    strMessage = "没有员工编号";
                    log.info("没有员工编号!!!!\n");
                    requestInfo.getRequestManager().setMessagecontent("没有员工编号");
                    return FAILURE_AND_CONTINUE;
                }
            }
            //******************************************

            //****************更新message*************************
            //获取message
            String returnMessage = strbuMess.toString();
            log.info("returnMessage值为:" + returnMessage + "\n");
            updatesql = "update " + tablename + " set sapfhxx= \'" + returnMessage + "\'  where requestid=" + requestid;
            log.info("更新sql语句："+updatesql);
            rs.executeQuery(updatesql);
            //根据返回值是否提交流程
            if (!"".equals(EPernr) && isSuccess) {
                log.info("成功！");
                log.info("入职流程接口日志结束=======>");
                return SUCCESS;
            } else {
                if (!"".equals(returnMessage)) {
                    requestInfo.getRequestManager().setMessagecontent(returnMessage);
                }
                log.info("入职流程接口日志结束=======>");
                return FAILURE_AND_CONTINUE;
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.info("入职流程接口日志结束=======>");
            return FAILURE_AND_CONTINUE;
        }

    }
}



